'''
数据序列化模块
'''

class ProtoMessageBase(object):
    '''
    所以数据的基类,所有序列化类都继承该类
    '''
    __slots__ = ('protoId',)
    def __init__(self,protoId):
        self.protoId = protoId       

    #设置 setitem getitem 这样可以通过字典模式访问属性   
    ''' 
    def __setitem__(self,key,value):
        self.__dict__[key] = value

    def __getitem__(self,key):
        return self.__dict__[key]
    '''
    def __repr__(self):
        s = '<'+self.__class__.__name__+":" 
        for key in self.__slots__:
            s += key +'='+str(getattr(self,key))+","  
        s = s[:len(s)-1]      
        s += '>'        
        return s

    def updateValues(self,values):        
        num = len(self.__slots__)
        for i in range(num):
            key = self.__slots__[i]          
            setattr(self,key,values[i])

class UserMessage(ProtoMessageBase):
    '''
    用户信息
    '''
    __slots__ = ('userId','desc') #设置属性列表 节省内存 设置后不能访问 __dict__ 了
    def __init__(self,protoId):
        super().__init__(protoId)       
        

